package com.cy.pj.arithmetic.service;

import com.cy.pj.arithmetic.common.exception.ServiceException;
import org.springframework.stereotype.Service;

@Service
public class ArithmeticService {
    public int sum(Integer... nums){
        if(nums==null||nums.length==0)
       // if(a<0 ||b<0)
            throw new ServiceException("数组不能为空");//自定义异常
        //return a+b;
        int sum=0;
        for(int i=0;i<=nums.length;i++){
            sum+=nums[i];
        }
        return sum;
    }
}
